# -*- coding: utf-8 -*-
# @Time    : 2019/10/18 13:17
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : getattr.py

# __getattr__, __getattribute__
# __getattr__ 就是在查找不到属性的时候调用
from datetime import date


class User:
    def __init__(self, name, birthday, info):
        self.Name = name
        self.birthday = birthday
        self.info = info

    def __getattr__(self, item):
        # 实例未查找到该属性时调用的魔法函数
        print(self.info[item])
        return self.info[item]  # 能够在传入的字典查询到属性

    # def __getattribute__(self, item):  # 实例查找属性优先进入该方法；所有属性的访问入口
    #     return "c1"   # 一般不要重写该方法，导致类实例化过程逻辑出错


if __name__ == '__main__':
    user = User("b1", date(year=1987, month=1, day=1), info={"company_name": "znufe", "name": "znufe1"})
    print(user.name)


